package Reflect;

import Reflect.zy.Test;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Comparator;

public class ReflectDemo10 {
    public static void main(String[] args) throws Exception{
        /**
         * 获取方法上的注解和注解属性值
         * getAnnotation(注解类型) 获取方法上的注解，返回注解对象
         */
        Class cls = Class.forName("Reflect.TestCase");
        Method[] methods = cls.getDeclaredMethods();
        Arrays.sort(methods, new Comparator<Method>() {
            @Override
            public int compare(Method method, Method t1) {
                Test a1 = method.getAnnotation(Test.class);
                Test a2 = t1.getAnnotation(Test.class);
                return a1.order()-a2.order();
            }
        });

        for (Method ms : methods){
            //获取方法上的注解
            Test a = ms.getAnnotation(Test.class);
            int value = a.order();//获取属性的值
            System.out.println(value);
        }

    }
}
